﻿using Nova_MOD;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nova_DAL
{
    public class WcsSysDal
    {
        DbHelper dbHelper = new DbHelper();

        public StoreProceResult GenternatePutCmd(string trayId, long SqId, int typeOfSzie, int flag)
        {
            DbCommand cmd = dbHelper.GetStoredProcCommond("dbo.SP_Generate_Input_CMDS_By_TRay_ID_100X_YMJX");
            dbHelper.AddInParameter(cmd, "@Tray_ID", DbType.String, trayId);
            dbHelper.AddInParameter(cmd, "@DEFAULT_TYPEOFSIZE", DbType.Int16, typeOfSzie);
            dbHelper.AddInParameter(cmd, "@DEFAULT_TYPEOFWEIGHT", DbType.Int16, 0);
            dbHelper.AddInParameter(cmd, "@SQIDS", DbType.Int64, SqId);
            dbHelper.AddInParameter(cmd, "@FLAG_1", DbType.Int16, flag);
            dbHelper.AddInParameter(cmd, "@MEMO", DbType.String, "");
            dbHelper.AddInParameter(cmd, "@User_Name", DbType.String, "");

            //输出参数
            dbHelper.AddOutParameter(cmd, "@TASKID", DbType.Int64, 100);
            dbHelper.AddOutParameter(cmd, "@ResNO", DbType.Int16, 100);
            dbHelper.AddOutParameter(cmd, "@ResMsg", DbType.String, 255);
            dbHelper.ExecuteNonQuery(cmd);
            int resNo = Convert.ToInt32(dbHelper.GetParameter(cmd, "@ResNO").Value.ToString());
            string resMessage = dbHelper.GetParameter(cmd, "@ResMsg").Value.ToString();
            StoreProceResult res = new StoreProceResult()
            {
                ResNo = resNo,
                ResMsg = resMessage
            };
            return res;
        }

        public StoreProceResult UpdateCmdState(long taskId, int xtype, int type)
        {
            DbCommand cmd = dbHelper.GetStoredProcCommond("dbo.SP_Update_CMDs");
            dbHelper.AddInParameter(cmd, "@TaskID", DbType.Int64, taskId);
            dbHelper.AddInParameter(cmd, "@XTYPE", DbType.Int16, xtype);
            dbHelper.AddInParameter(cmd, "@HType", DbType.Int16, type);
            dbHelper.AddInParameter(cmd, "@UserName", DbType.String, "");

            //输出参数
            dbHelper.AddOutParameter(cmd, "@ResNO", DbType.Int16, 100);
            dbHelper.AddOutParameter(cmd, "@ResMsg", DbType.String, 255);
            dbHelper.ExecuteNonQuery(cmd);
            int resNo = Convert.ToInt32(dbHelper.GetParameter(cmd, "@ResNO").Value.ToString());
            string resMessage = dbHelper.GetParameter(cmd, "@ResMsg").Value.ToString();
            StoreProceResult res = new StoreProceResult()
            {
                ResNo = resNo,
                ResMsg = resMessage
            };
            return res;
        }

        public StoreProceResult GenternateMoveCmd(int lane,int rows,int cols,int layers)
        {
            DbCommand cmd = dbHelper.GetStoredProcCommond("dbo.SP_GMoveByExtension_Pro_YMJX");
            dbHelper.AddInParameter(cmd, "@Lane", DbType.Int64, lane);
            dbHelper.AddInParameter(cmd, "@RowS", DbType.Int16, rows);
            dbHelper.AddInParameter(cmd, "@ColS", DbType.Int16, cols);
            dbHelper.AddInParameter(cmd, "@LayerS", DbType.Int16, layers);
            dbHelper.AddInParameter(cmd, "@UserName", DbType.String, "");

            //输出参数
            dbHelper.AddOutParameter(cmd, "@ResNO", DbType.Int16, 100);
            dbHelper.AddOutParameter(cmd, "@ResMsg", DbType.String, 255);
            dbHelper.ExecuteNonQuery(cmd);
            int resNo = Convert.ToInt32(dbHelper.GetParameter(cmd, "@ResNO").Value.ToString());
            string resMessage = dbHelper.GetParameter(cmd, "@ResMsg").Value.ToString();
            StoreProceResult res = new StoreProceResult()
            {
                ResNo = resNo,
                ResMsg = resMessage
            };
            return res;
        }

    }
}
